package com.luo.stock.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Author 奥观海
 * @Date 2024/9/20
 */
@Configuration
public class MqConfig {
    /**
     * 重新定义消息序列化的方式，改为基于json格式序列化和反序列化
     * @return
     */
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }
    @Bean
    public TopicExchange stockExchange (){
        return new TopicExchange("stockExchange");
    }
    /**
     * 国内大盘
     * @return
     */
    @Bean
    public Queue innerMarketQueue(){
        return new Queue("innerMarketQueue",true);
    }


    @Bean
    public Binding innerMarketBinging(){
        return BindingBuilder.bind(innerMarketQueue()).to(stockExchange())
                .with("innerMarket.key");
    }
    /**
     * 国内大盘
     * @return
     */
    @Bean
    public Queue outerMarketQueue(){
        return new Queue("outerMarketQueue",true);
    }

    @Bean
    public Binding outerMarketBinging(){
        return BindingBuilder.bind(outerMarketQueue()).to(stockExchange())
                .with("outerMarket.key");
    }
    /**
     * 国内板块
     * @return
     */
    @Bean
    public Queue innerStockBlockQueue(){
        return new Queue("innerStockBlockQueue",true);
    }

    @Bean
    public Binding innerStockBlockBinging(){
        return BindingBuilder.bind(innerStockBlockQueue()).to(stockExchange())
                .with("innerStockBlock.key");
    }
    /**
     * 国内股票
     * @return
     */
    @Bean
    public Queue innerStockQueue(){
        return new Queue("innerStockQueue",true);
    }

    @Bean
    public Binding innerStockBinging(){
        return BindingBuilder.bind(innerStockQueue()).to(stockExchange())
                .with("innerStock.key");
    }
}
